/*============================================================================
* Author        : Li Ji
* Mail          : leejearl@126.com
* Last modified : 2015-02-08 18:10
* Filename      : CConfig.cpp
* Description   :
*
=============================================================================*/

#include "CConfig.hpp"
#include <fstream>
#include <sstream>
#include <stdexcept>
#include <iostream>
using namespace std;
CConfig::CConfig(std::string aCfg) : _cfg(aCfg)
{
}

void CConfig::addOption(const std::string name, long int & option_field, 
        long int default_value)
{
}

void CConfig::init()
{
    ifstream in;
    in.open(_cfg.c_str());
    if(in.is_open())
    {
        string textline;

        // Get _nDim
        while(getline(in, textline))
        {
            if(textline != "")
            {
                stringstream read;
                read.str(textline);
                read >> _nDim;
                break;
            }
        }

        // Get _meshFile
        while(getline(in, textline))
        {
            if(textline != "")
            {
                stringstream read;
                read.str(textline);
                read >> _meshFile;
                break;
            }
        }

        // Get _outMeshFile
        while(getline(in, textline))
        {
            if(textline != "")
            {
                stringstream read;
                read.str(textline);
                read >> _outMeshFile;
                break;
            }
        }

        // Get _solver
        while(getline(in, textline))
        {
            if(textline != "")
            {
                stringstream read;
                read.str(textline);
                read >> _solver;
                break;
            }
        }

        // Get _nMarker
        while(getline(in, textline))
        {
            if(textline != "")
            {
                stringstream read;
                read.str(textline);
                read >> _nMarker;
                _markerTypes.resize(_nMarker);
                for(long int iMarker = 0; iMarker < _nMarker; iMarker++)
                {
                    getline(in, textline);
                    read.clear();
                    read.str(textline);
                    read >> _markerTypes[iMarker];
                }

                break;
            }
        }

        in.close();
    } else
    {
        throw runtime_error("The config-file " + _cfg + " is not opened correctly!\n");
    }

}

